package com.hsp.Demo_05_extends;

import com.hsp.Demo_05_extends.teacher.Person;

public class Demo_05 {
    public static void main(String[] args) {
        /*
        判断两个Person对象是否相等。要求，只要这两个对象中的属性都相同，则意味着这两个对象相等。
        */

        Person_05 p1 = new Person_05("jack", 18, '男');
        Person_05 p2 = new Person_05("jack", 18, '男');
        System.out.println(p1 == p2);

        System.out.println(p1.equals(p2));

        System.out.println((int)'A');

        System.out.println(p1);
        System.out.println(p1.toString());

    }
}

class Person_05{
    private String name;
    private int age;
    private char gender;

    public Person_05(String name, int age, char gender){
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }

        if(!(this instanceof Object)){
            return false;
        }

            Person_05 p = (Person_05)obj;
            return this.name.equals(p.name)&&this.age == p.age && this.gender == p.gender;
    }

    @Override
    public String toString() {
        return "Person_05{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }
}